package com.lanyou.esb.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public final class DateUtils {
	/** 获取日期，格式为：yyyyMMddHHmmss **/
	public static final SimpleDateFormat DATEPATTERN_YYYYMMDDHHMMSS = new SimpleDateFormat(
			"yyyyMMddHHmmss");
	/** 获取日期，格式为：yyyyMMddHHmm **/
	public static final SimpleDateFormat DATEPATTERN_YYYYMMDDHHMM = new SimpleDateFormat(
			"yyyyMMddHHmm");
	/** 获取日期，格式为：yyyyMMddHH **/
	public static final SimpleDateFormat DATEPATTERN_YYYYMMDDHH = new SimpleDateFormat(
			"yyyyMMddHH");
	/** 获取日期，格式为：yyyyMMdd **/
	public static final SimpleDateFormat DATEPATTERN_YYYYMMDD = new SimpleDateFormat(
			"yyyyMMdd");
	/** 获取日期，格式为：yyyyMM **/
	public static final SimpleDateFormat DATEPATTERN_YYYYMM = new SimpleDateFormat(
			"yyyyMM");

	/** 获取日期，格式为：yyyy **/
	public static final SimpleDateFormat DATEPATTERN_YEAR = new SimpleDateFormat(
			"yyyy");
	/** 获取日期，格式为：MM **/
	public static final SimpleDateFormat DATEPATTERN_MONTH = new SimpleDateFormat(
			"MM");
	/** 获取日期，格式为：dd **/
	public static final SimpleDateFormat DATEPATTERN_DAY = new SimpleDateFormat(
			"dd");
	/** 获取日期，格式为：HH **/
	public static final SimpleDateFormat DATEPATTERN_HOUR = new SimpleDateFormat(
			"HH");
	/** 获取日期，格式为：mm **/
	public static final SimpleDateFormat DATEPATTERN_MINUTE = new SimpleDateFormat(
			"mm");
	/** 获取日期，格式为：ss **/
	public static final SimpleDateFormat DATEPATTERN_SECOND = new SimpleDateFormat(
			"ss");

	public static boolean isSameDay(Date date1, Date date2) {
		if (date1 == null || date2 == null) {
			return false;
		}
		Calendar date1Calendar = Calendar.getInstance();
		date1Calendar.setTime(date1);
		date1Calendar.set(Calendar.MINUTE, 0);
		date1Calendar.set(Calendar.SECOND, 0);
		date1Calendar.set(Calendar.MILLISECOND, 0);

		Calendar date2Calendar = Calendar.getInstance();
		date2Calendar.setTime(date2);
		date2Calendar.set(Calendar.MINUTE, 0);
		date2Calendar.set(Calendar.SECOND, 0);
		date2Calendar.set(Calendar.MILLISECOND, 0);

		return date1Calendar.compareTo(date2Calendar) == 0;
	}
}
